﻿<UserControl x:Class="WpfImageDuplicates.GroupsViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:y="clr-namespace:WpfImageDuplicates"
             xmlns:dragdrop="clr-namespace:DragDropLibrary;assembly=DragAndDrop"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 
             mc:Ignorable="d">
    <!--dragdrop:DragAndDrop.DropMethodName="DropOntoImageCollectionView"-->
    <Grid Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="16"/>
            <RowDefinition Height="24"/>
            <RowDefinition Height="24"/>
            <RowDefinition Height="*"/>            
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" HorizontalAlignment="Right">
            <Button x:Name="btnCloseView" Content="X" Click="btnCloseView_Click" Padding="4,0,4,0" Margin="0" ToolTip="Close View"  FontSize="8"/>
        </Grid>
        <Grid Grid.Row="1">
            <ToggleButton x:Name="btnAddGroup" Content="Add Group" Checked="btnAddGroup_Checked"
                          Visibility="{Binding Mode=OneWay, ElementName=groupNameStack, Converter={StaticResource VisibilityConverter}, ConverterParameter=NOT}"/>
            <StackPanel x:Name="groupNameStack" Orientation="Horizontal"
                        Visibility="{Binding Mode=OneWay, ElementName=btnAddGroup, Path=IsChecked, Converter={StaticResource VisibilityConverter}, ConverterParameter=NOT}">
                <TextBlock Text="Name: " VerticalAlignment="Center" FontSize="10" />
                <TextBox x:Name="txtNewGroupName" KeyDown="txtNewGroupName_KeyDown" MinWidth="80" VerticalAlignment="Center" FontSize="10" />
                <TextBlock Text=" " VerticalAlignment="Center" />
                <Button x:Name="btnCreateNewGroup" Content="Create" Click="btnCreateNewGroup_Click" VerticalAlignment="Center" Padding="2,1,2,1" FontSize="10"/>
            </StackPanel>
        </Grid>
        <Grid Grid.Row="2">
            <ToggleButton x:Name="btnShowOnlySelectedGroups" Checked="btnShowOnlySelectedGroups_Checked" Unchecked="btnShowOnlySelectedGroups_Unchecked" Content="Show only selected groups"/>
        </Grid>
        <ListBox x:Name="lstGroups" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Row="3"
                 dragdrop:DragAndDrop.RegisterDragSourceName="ImageCollectionView" 
                 dragdrop:DragAndDrop.RegisterDropTargetName="GroupView"
                 dragdrop:DragAndDrop.DropMethodName="DropOntoImageCollectionView"    
                 dragdrop:DragAndDrop.DropEnabled="True"                                                                         
                 SelectionMode="Extended" 
                 SelectionChanged="lstGroups_SelectionChanged"
                 >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid x:Name="subGrid" Loaded="subGrid_Loaded">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="24"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="24"/>
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="0">
                            <CheckBox x:Name="chkSelect" IsChecked="{Binding Mode=OneWay, Path=IsSelected}" Checked="chkSelect_Checked" Unchecked="chkSelect_Unchecked" 
                                      Tag="{Binding}"/>
                        </Grid>
                        <Grid Grid.Column="1">
                            <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding GroupName}" Tag="{Binding}" Cursor="Hand" TextDecorations="Underline"
                                       x:Name="txtGroupName" MouseLeftButtonDown="txtGroupName_MouseLeftButtonDown">
                                <TextBlock.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Header="_Delete Group" x:Name="mnuDeleteGroup" Click="mnuDeleteGroup_Click" Tag="{Binding}"/>
                                    </ContextMenu>
                                </TextBlock.ContextMenu>
                            </TextBlock>
                        </Grid>                        
                        <Grid Grid.Column="2">
                            <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Count}" Tag="{Binding}"/>
                        </Grid>
                        <Grid Grid.Row="1" x:Name="listOfFiles" Visibility="Collapsed" Grid.ColumnSpan="3">
                            <ListBox x:Name="lstFileImagesInGroup" ItemsSource="{Binding FileImages}" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                     SelectionMode="Extended">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid x:Name="subGrid2" Loaded="subGrid_Loaded">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="4"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="16"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid Grid.Column="1">
                                                <TextBlock Text="{Binding FileNameOnly}" VerticalAlignment="Center" />                                                
                                            </Grid>
                                            <Image Grid.Column="2" Source="/WpfImageDuplicates;component/Images/Symbol%20Delete%202.png" Width="14" Stretch="Uniform"
                                                   Tag="{Binding}"
                                                   Cursor="Hand" x:Name="removeFileImage" MouseLeftButtonDown="removeFileImage_MouseLeftButtonDown"/>
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </Grid>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

    </Grid>
</UserControl>
